<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<script type="text/javascript">
    $(function () {
        $("#view").on('click', function () {
            hideShowTableTd('countDrugTable', '0,2,3,4', '2');
            $("#LeftDiv").attr("class", "main-content col-lg-0");
            $("#RightDiv").show('normal');
            return loadDiv('rigthCenterDiv', '${ctx}/orders/orders/dispOrderDetails');
        });
        $("#print").on('click',function(){
        var wardCode = $("#wardCode").val();
            printPdf('${ctx}/orders/orders/dispPrint?wardCode='+wardCode);
        })
        var qFlag=false;
        $("#queryBtn").on('click', function () {
            if(qFlag){
                toastr.error("数据正在准备中,请稍后点击查询");
            }
            qFlag=true;
//            var wardCode=$("input[name=wardCode]").val();
            var days=$("#days").val();
//            if(wardCode==null || wardCode==''){
//                toastr.error("请选择摆药病区");
//                qFlag=false;
//                return false;
//            }
            $("#searchOrdersDisp").submit();
            qFlag=false;
        })
        //摆药保存
        var flag = false;
        $("#dispSave").on('click', function () {
            flag = true;
            var dispNo = $("#dispNo").val();
            var days = $("#days").val();
            var storageId = $("#storageId").val();
            if (dispNo == null || dispNo == "") {
                toastr.error("获取摆药序号失败");
                return false;
            }
            if (flag) {
                $.ajax({
                    type: "POST",
                    url: "${ctx}/orders/orders/dispSave?dispNo=" + dispNo + "&storageId=" + storageId + "&days=" + days,
                    dataType: "json",
                    success: function (data) {
                        flag = false;
                        if (data.code == "success") {
                            toastr.success(data.message);
                            $("#searchOrdersDisp").submit();
                        } else if (data.code == 'error') {
                            toastr.error("库存不足");
                        }
                    }, error: function (data) {
                        toastr.error(data.message);
                        toastr.error('网络连接错误,请检查网络');
                        flag = false;
                    }
                });
            } else {
                toastr.error('摆药正在进行中,请稍后重试');
            }
        })
    })
    /**
     * 查看医嘱明细数量
     */
</script>
<div class="app">
    <section class="layout">
        <section class="main-content col-lg-12" id="LeftDiv">
            <div class="content-wrap">
                <div class="wrapper" style="bottom: 50px;">
                    <ul class="nav nav-tabs">
                        <li>
                            <a href="#">药品汇总列表</a>
                        </li>
                    </ul>
                    <section class="panel panel-default">
                        <div class="panel-body">
                            <div class="table-responsive no-border">
                                <div class="datatable-top">
                                    <div class="pull-left">
                                        <form:form id="searchOrdersDisp" modelAttribute="orders"
                                                   onsubmit="return loadDivForm('mainCenterDiv','searchOrdersDisp','${ctx}/orders/orders/dispIndex');"
                                                   method="post" class="form-inline">
                                            <form:hidden path="storageId" value="${storageId}"/>
                                            病区选择:
                                            <sys:treeselect selectedParent="false" id="orders" name="wardCode"
                                                            value="${orders.wardCode}" update="false"
                                                            labelName="${orders.wardCode}"
                                                            labelValue="${orders.deptName}"
                                                            title="病区选择" url="/sys/orgDept/treeData?clinicAttrs=2"
                                                            cssClass="form-control"/>
                                            <form:select path="administration"
                                                         class="form-control">
                                                <form:option value="" label="全部"/>
                                                <form:option value="1" label="服药类"/>
                                                <form:option value="2" label="注射类"/>
                                                <form:option value="3" label="输液类"/>
                                            </form:select>
                                            摆药天数：
                                            <input type="number" min="1" max="15" id="days" size="3"
                                                   class="form-control input-sm spinner-input"
                                                   name="days" placeholder="请输入摆药天数" value="${orders.days}">
                                            住院号：<input type="number" min="1" class="form-control input-sm spinner-input"
                                            name="visitNo" placeholder="请输入病人住院号" value="${orders.visitNo}">
                                            床位号:<input type="text" class="form-control input-sm spinner-input"
                                                   name="bedNo" size="6" placeholder="以逗号或者是中划线分割" value="${orders.bedNo}">
                                            <input id="queryBtn" class="btn btn-primary" type="button" value="查询"/>
                                            <input id="dispSave" class="btn btn-primary" type="button" value="摆药保存"/>
                                            <input id="view" class="btn btn-primary" type="button" value="详情"/>
                                            <input id="print" class="btn btn-primary" type="button" value="打印"/>
                                        </form:form>
                                    </div>
                                </div>
                                <%--药品汇总列表--%>
                                <table id="countDrugTable" class="table table-bordered mg-t datatable">
                                    <thead>
                                    <tr>
                                        <th>摆药序号</th>
                                        <th>摆药天数</th>
                                        <th>药品名称</th>
                                        <th>单价</th>
                                        <th>包装规格</th>
                                        <th>包装单位</th>
                                        <th>药品厂商</th>
                                        <th>摆药数量</th>
                                        <th>库存量</th>
                                        <th>摆药说明</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <c:forEach items="${countDrugListPage}" var="drug">
                                        <tr style="text-align: center;">
                                            <td>
                                                    ${drug.dispNo}
                                            </td>

                                            <td>
                                                    ${drug.days}
                                            </td>

                                            <td>
                                                    ${drug.drugName}
                                            </td>
                                            <td>
                                                    ${drug.price}
                                            </td>
                                            <td>
                                                    ${drug.drugSpec}
                                            </td>
                                            <td>
                                                    ${drug.drugUnits}
                                            </td>
                                            <td>
                                                    ${drug.firmName}
                                            </td>
                                            <td>
                                                    ${drug.amount}
                                            </td>
                                            <td>
                                                <c:if test="${drug.redFlag==1}">
                                                    <font color="red">${drug.stock}(${drug.drugUnits})</font>
                                                </c:if>
                                                <c:if test="${drug.redFlag==0}">
                                                    ${drug.stock}(${drug.drugUnits})
                                                </c:if>
                                            </td>
                                            <td>
                                                <c:if test="${drug.redFlag==1}">
                                                    <font color="red">库存量不足</font>
                                                </c:if>
                                                <c:if test="${drug.redFlag==0}">
                                                    正常摆药
                                                </c:if>
                                            </td>
                                        </tr>
                                    </c:forEach>
                                    </tbody>
                                </table>
                                <input type="hidden" id="dispNo" value="${orders.dispNo}">
                            </div>
                        </div>
                    </section>
                </div>
            </div>
        </section>
        <%--右侧医嘱明细列表--%>
        <section class="main-content col-lg-12" style="display: none" id="RightDiv">
            <div class="content-wrap" id="rigthCenterDiv">
            </div>
        </section>
    </section>

</div>

